package thread;

import java.util.concurrent.Semaphore;

public class ThreadDemo11 {

    public static void main(String[] args) throws InterruptedException{
        Semaphore semaphore = new Semaphore(3); //指定计数器个数是3
        semaphore.acquire(); //执行P操作
        System.out.println("P操作一次");

        semaphore.acquire(); //执行P操作
        System.out.println("P操作一次");

        semaphore.acquire(); //执行P操作
        System.out.println("P操作一次");

        semaphore.release(); //执行V操作

        semaphore.acquire(); //执行P操作
        System.out.println("P操作一次");


    }
}
